package com.gitee.wsl.mathematics.function.randomForest


/**
 * @author lidapeng
 * @description 内存数据表
 * @date 3:48 下午 2020/2/17
 */
class DataTable(var keyType: MutableSet<String>) {
    //数据表
    val table: MutableMap<String, MutableList<Int>> = HashMap()
    //var keyType: Set<String>? = null //表的属性

    @set:Throws(Exception::class)
    var key: String? = null //最终分类字段
        set(key) {
            if (keyType.contains(key!!)) {
                field = key
            } else {
                throw Exception("NOT FIND KEY")
            }
        }
    var length: Int = 0
        private set

    val size: Int
        get() =//获取属性的数量
            keyType.size

//    fun getTable(): Map<String, MutableList<Int>> {
//        return table
//    }

    init { //表的属性
        //this.keyType = key
        for (name in keyType) {
            table[name] = ArrayList<Int>()
        }
    }


    fun insert(ob: Any) {
        //try {
        //    val body: java.lang.Class<*> = ob.javaClass
        //    length++
        //    for (name in keyType!!) {
        //        val methodName = "get" + name.substring(0, 1)
        //            .uppercase(java.util.Locale.getDefault()) + name.substring(1)
        //        val method: java.lang.reflect.Method = body.getMethod(methodName)
        //        val dm: Any = method.invoke(ob)
        //        val list = table[name]!!
        //        if (dm is Int) { //数据表只允许加入Integer类型数据
        //            list.add(dm)
        //        } else {
        //            throw java.lang.Exception("数据表只允许加入Integer类型数据")
        //        }
        //    }
        //} catch (e: java.lang.Exception) {
        //    e.printStackTrace()
        //}
    }
}
